<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <div th:include="base-libs :: base-libs" />
    <title>双向转诊台账—新增转入</title>

    <script th:src="@{/tbxt/js/easyui_editModel.js}"></script>
    <script th:src="@{/tbxt/js/TzUtils.js}"></script>

    <style>
        .spanBtn{
            font-weight: bold;
            color: blue;
            cursor:pointer;
        }
    </style>

    <script>
        var zzlxArr,jjcdArr;//转诊类型Arr，紧急程度Arr
        var sfqyArr = [{XMDM:'1',"XMMC":'已签约'},{XMDM:'2',"XMMC":'未签约'}];
        var sflyArr = [{XMDM:'3',"XMMC":'已履约'},{XMDM:'2',"XMMC":'未履约'}];
        var $addTb;

        $(function(){
            $addTb = $("#addTb");
            $(this).registerManagerPage({cacheTables:["TB_ZY_ZZLX","TB_ZY_JJCD"],callback:initView});
        })

        function initView(){
            zzlxArr = StoreCache.getCache("TB_ZY_ZZLX").data;
            jjcdArr = StoreCache.getCache("TB_ZY_JJCD").data;

            /* 模板表格 */
            $("#modelTb").datagrid({
                fitColumns: true,
                fit:true,
                scrollbarSize:10,
                rownumbers: true,
                columns : [[
                    {field : "ZZYYSJ",title : "2017-07-02",width:80,align:'center'},
                    {field : "XM",title : "张三",width:65,align:'center'},
                    {field : "SFZH",title : "411722197508214024",width:130,align:'center'},
                    {field : "SJHM",title : "南昌市第一医院",width:160,align:'left'},
                    {field : "JTZZ",title : "外科",width:100,align:'center'},
                    {field : "RQFL",title : "门诊转诊",width:60,align:'center'},
                    {field : "QYTD",title : "普通",width:60,align:'center'},
                    {field : "QYFWB",title : "已履约",width:60,align:'center'},
                    {field : "QYFWB2",title : "2017-07-05",width:80,align:'center'},
                    {field : "QYFWB1",title : "已签约",width:80,align:'center'},
                    {field : "cz",title : "",width:50,align:'center'}
                ]]
            });

            /** 添加表格  */
            $addTb.datagrid({
                striped : true,
                clickToSelect: true,
                fitColumns: true,
                singleSelect: true,
                fit:true,
                scrollbarSize:10,
                rownumbers: true,
                columns : [[
                    {field : "ZZYYSJ",title : "转诊预约时间",width:80,align:'center',
                        editor:{
                            type: "laydate",
                            options:{
                                label: '转诊预约时间',
                                validateProxy:'notNull D10',
                            }
                        }
                    },
                    {field : "XM",title : "患者姓名",width:65,align:'center',
                        editor:{
                            type: "quickTextValidate",
                            options:{
                                label: '患者姓名',
                                length:32,
                                validateProxy:'notNull length',
                            }
                        }
                    },
                    {field : "SFZH",title : "证件号码",width:130,align:'center',
                        editor:{
                            type: "quickTextValidate",
                            options:{
                                label: '证件号码',
                                length:32,
                                validateProxy:'notNull idCard length',
                            }
                        }
                    },
                    {field : "ZCYY",title : "转出医院",width:160,align:'left',
                        editor:{
                            type: "quickTextValidate",
                            options:{
                                label: '转入医院',
                                length:128,
                                validateProxy:'notNull length',
                            }
                        }
                    },
                    {field : "ZCKS",title : "转出科室",width:100,align:'center',
                        editor:{
                            type: "quickTextValidate",
                            options:{
                                label: '转入科室',
                                length:128,
                                validateProxy:'notNull length',
                            }
                        }
                    },
                    {field : "ZZLX",title : "转诊类型",width:60,align:'center',
                        formatter:function(value,row){
                            $.each(zzlxArr, function(i, item){
                                if(item.XMMC==value){
                                    row.ZZLX = item.XMDM;
                                    return false;
                                }
                                if(item.XMDM==value){
                                    value = item.XMMC;
                                    return false;
                                }
                            })
                            return value;
                        },
                        editor:{
                            type: "quickSelectValidate",
                            options:{
                                valueField:'XMDM',
                                textField:'XMMC',
                                data: zzlxArr,
                                label: '转诊类型',
                                validateProxy:'notNull',
                            }
                        }
                    },
                    {field : "JJCD",title : "紧急程度",width:60,align:'center',
                        formatter:function(value,row){
                            $.each(jjcdArr, function(i, item){
                                if(item.XMMC==value){
                                    row.JJCD = item.XMDM;
                                    return false;
                                }
                                if(item.XMDM==value){
                                    value = item.XMMC;
                                    return false;
                                }
                            })
                            return value;
                        },
                        editor:{
                            type: "quickSelectValidate",
                            options:{
                                valueField:'XMDM',
                                textField:'XMMC',
                                data: jjcdArr,
                                label: '紧急程度',
                                validateProxy:'notNull',
                            }
                        }
                    },
                    {field : "SFLY",title : "是否履约",width:60,align:'center',
                        formatter:function(value,row){
                            $.each(sflyArr, function(i, item){
                                if(item.XMMC==value){
                                    row.SFLY = item.XMDM;
                                    return false;
                                }
                                if(item.XMDM==value){
                                    value = item.XMMC;
                                    return false;
                                }
                            })
                            return value;
                        },
                        editor:{
                            type: "quickSelectValidate",
                            options:{
                                valueField:'XMDM',
                                textField:'XMMC',
                                data: sflyArr,
                                label: '是否履约',
                                validateProxy:'notNull',
                            }
                        }
                    },
                    {field : "LYSJ",title : "履约时间",width:80,align:'center',
                        editor:{
                            type: "laydate",
                            options:{
                                label: '履约时间',
                                validateProxy:'notNull D10',
                            }
                        }
                    },
                    {field : "SFQY",title : "是否签约",width:80,align:'center',
                        formatter:function(value,row){
                            $.each(sfqyArr, function(i, item){
                                if(item.XMMC==value){
                                    row.SFQY = item.XMDM;
                                    return false;
                                }
                                if(item.XMDM==value){
                                    value = item.XMMC;
                                    return false;
                                }
                            })
                            return value;
                        },
                        editor:{
                            type: "quickSelectValidate",
                            options:{
                                valueField:'XMDM',
                                textField:'XMMC',
                                data: sfqyArr,
                                label: '是否签约',
                                validateProxy:'notNull',
                            }
                        }
                    },

                    {field : "cz",title : "操作",width:50,align:'center', formatter:function(value,row,index){
                        return TzUtils.formatZcBtn(index);
                    }}
                ]],
                onClickRow : function(rowIndex, row){
                    var editRowNum = $(this).data("editRowNum");
                    if(!StringUtils.isEmpty(editRowNum) && rowIndex != editRowNum){
                        //不做数据验证（避免和添加按钮中的验证重复）
                        $(this).datagrid('endEdit', editRowNum).datagrid('beginEdit', rowIndex)
                            .data("editRowNum",rowIndex);
                    }
                },
            });

            /** 添加一行  */
            $("body").on("click",".btnTj",function(){
                TzUtils.addRow();
            })

            /** 删除一行  */
            $("body").on("click",".btnSc",function(){
                TzUtils.deleteRow();
            })

            /** 提交 */
            $("#btnTj").click(function () {
                TzUtils.save(contextRoot + "sxzztz/save", {ZZBS:"2"});
            })

            /** 返回 */
            $("#btnFh").click(function () {
                $.QuickUrlUtils.redirectUrl("index.html");
            })

            /** 导入 */
            $("#btnDr").click(function () {
                StoreCache.setCache("importType","zrExcel");
                TzUtils.openImpotView(contextRoot + 'sxzztz/import.html');
            })

            /** 下载模板 */
            $("#btnXzmb").click(function () {
                $("#formXzmb").submit();
            })

            //改变样例表格样式
            TzUtils.format_modelTbStyle();

            //默认添加一行
            TzUtils.addRow();

            /* 是否履约和履约时间--联动 */
            $("select:eq(2)").change(function(){
                var value = $(this).val();
                if(value == 2){
                    $(".laydate-icon:last").removeClass("easyuiEditText").css("borderColor","#B6B6B6");
                }else{
                    $(".laydate-icon:last").addClass("easyuiEditText");
                }

            })
            //验证一行前
            TzUtils.otherThing = function(){
                $("select:eq(2)").trigger("change");
            }
        }


    </script>
</head>
<body class="easyui-layout" fit="true">
<div region="north" style="height:80px;border:0;overflow: hidden">
    <h3 style="font-size:14px;padding: 15px 0px 3px 15px;">
        <span id="haha"></span>
        <span style="font-weight: bold;letter-spacing:0.5px">请按以下格式新增双向转诊<span style="color:red">转入记录</span>：</span>
        <button id="btnXzmb" class="btn btn-info" type="button" style="float:right;margin-right:35px;margin-left:0px;position:relative;top:-8px">下载模板</button>
        <button id="btnDr" class="btn btn-info" type="button" style="float:right;margin-right:8px;position:relative;top:-8px">导入</button>
    </h3>
    <table id="modelTb"></table>
</div>
<div region="center" border="false">
    <table id="addTb"></table>
</div>
<div region="south" style="height:40px;line-height:40px;border:0;border-top:1px solid #ddd;text-align: center;overflow: hidden">
    <button id="btnTj" class="btn btn-info" type="button">提交</button>
    <button id="btnFh" class="btn btn-info" type="button">返回</button>
</div>

<form id="formXzmb" action="downExcelModel.service?type=zrModel" method="post" enctype="multipart/form-data"></form>
<form id="formDr" action="parseExcalData.service" method="post" enctype="multipart/form-data" style="opacity: 0;display: none">
    <input id="fileField" type="file" name="fileField"  />
</form>

</body>
</html>